package com.kgcx.schedule.rabbitmq.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.rabbitmq.bean.Message;
import com.kgcx.common.rabbitmq.consts.ExchangeConst;
import com.kgcx.common.rabbitmq.consts.RoutingKeyConst;
import com.kgcx.dbutils.core.model.ParameterMap;
import com.kgcx.schedule.domain.DriverInfoDomain;

import lombok.extern.slf4j.Slf4j;

/**
 * @author 袁进勇
 * @date 2017/11/27
 */
@Slf4j
@Component
public class DriverStateProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void login(DriverInfoDomain driverInfo, String lng, String lat) {
        ParameterMap params = new ParameterMap();
        params.put("licenseId", driverInfo.getDriver_license_id());
        params.put("autoNo", driverInfo.getAuto_no());
        params.put("lng", lng);
        params.put("lat", lat);
        Message msg = Message.buildMessage("operateLogin", Message.FLAG_ADD, params);
        String json = JSONObject.toJSONString(msg);

        log.info(String.format("发送车辆运营上线成功的MQ消息，车辆ID[%d]，司机ID[%d]。%s", driverInfo.getAuto_id(),
                driverInfo.getDriver_id(), json));
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON, json);
    }

    public void logout(DriverInfoDomain driverInfo, String lng, String lat) {
        ParameterMap params = new ParameterMap();
        params.put("licenseId", driverInfo.getDriver_license_id());
        params.put("autoNo", driverInfo.getAuto_no());
        params.put("lng", lng);
        params.put("lat", lat);
        Message msg = Message.buildMessage("operateLogout", Message.FLAG_ADD, params);
        String json = JSONObject.toJSONString(msg);

        log.info(String.format("发送车辆运营下线成功的MQ消息，车辆ID[%d]，司机ID[%d]。%s", driverInfo.getAuto_id(),
                driverInfo.getDriver_id(), json));
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON, json);
    }

}
